<?php

use App\Exceptions\ApiException;
use App\Http\Controllers\Api\CourseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});
Route::prefix('v1')->name('api.v1')->namespace('Api')->group(function(){
    Route::get('test',function(){
        apiErr("课程不存在");
    })->name('test');
    
    Route::post('login', '\App\Http\Controllers\Admin\LoginController@check')->name('login');
    
    // 课程集合
    Route::get('courses',[CourseController::class,'index'])->name('courses');

    // 课程信息
    Route::get('courses/{course}',[CourseController::class,'course'])->name('course');

    // 资源
    Route::get('courses/{course}/resource/{resource}',[CourseController::class,'resource'])->name('resource');

    // 测试视频播放凭证的路由
    Route::post('test-video-play-auth',[CourseController::class,'testVideoPlayAuth']);
    
    // 测试视频播放地址的路由
    Route::post('test-video-play-info',[CourseController::class,'testVideoPlayInfo']);
    
    // 课程搜索路由
    Route::get('search',[CourseController::class,'search'])->name('search');
});